<?php
/**
 * Created by PhpStorm.
 * User: eric
 * Date: 10/10/14
 * Time: 1:44 PM
 */

include_once "DateTimeFormat.php";

class SmartDateTime extends DateTime {

    public function compareTo($smartDateTime)
    {
        //return strcmp(parent::format(DateTimeFormat::sql_datetime), $smartDateTime->format(DateTimeFormat::sql_datetime));
        return strcmp(self::getTimestamp()."", $smartDateTime->getTimestamp()."");
    }

    public function equals($smartDateTime)
    {
        return (self::getTimestamp() == $smartDateTime->getTimestamp());
    }
    //[HOUR]
    public function addHours($hours)
    {
        return $this->add(DateInterval::createFromDateString($hours." hour"));
    }

    public function subHours($hours)
    {
        return $this->sub(DateInterval::createFromDateString($hours." hour"));
    }
    //[MINUTE]
    public function addMinutes($minutes)
    {
        return $this->add(DateInterval::createFromDateString($minutes." minutes"));
    }

    public function subMinutes($minutes)
    {
        return $this->sub(DateInterval::createFromDateString($minutes." minutes"));
    }
    //[DAY]
    public function addDays($days)
    {
        return $this->add(DateInterval::createFromDateString($days." days"));
    }

    public function subDays($days)
    {
        return $this->sub(DateInterval::createFromDateString($days." days"));
    }

    public function getDate()
    {
        return (int)$this->format(DateTimeFormat::DAY_01_to_31);
    }
    public function getMonth()
    {
        return (int)$this->format(DateTimeFormat::MONTH_01_to_12);
    }

    public function getYear()
    {
        return (int)$this->format(DateTimeFormat::YEAR_19xx_to_2xxx);
    }

    public function getHour()
    {
        return (int)$this->format(DateTimeFormat::HOUR_00_to_23);
    }

    public function getMinute()
    {
        return (int)$this->format(DateTimeFormat::MINUTE);
    }

    public function getSecond()
    {
        return (int)$this->format(DateTimeFormat::SECOND);
    }

    /**/

    //any year, month from 1 to 12
    public static function DaysInMonth($year, $month)
    {
        $date = new SmartDateTime();
        $day = 1;
        $date->setDate($year, $month, $day);

        return (int)$date->format(DateTimeFormat::MONTH_number_of_days);
    }

    public static function getDateList($year, $month=-1)
    {
        if ($month = -1)
        {
            //get all day in year
        }
        else
        {
            //get all day in the specific month
        }

    }
}
